<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends CommonController {

    public function test()
    {


        M()->startTrans();

        $sql =" insert into test (name) VALUES('bbbb1')";
        M()->execute($sql);

        $sql =" insert into test (name) VALUES('bbbb2')";
        M()->execute($sql);
        $sql =" insert into test (name) VALUES('bbbb3')";
        M()->execute($sql);
        $sql =" insert into test (name) VALUES('bbbb4')";

        M()->execute($sql);

        M()->commit();





        // $id = I('get.id');

        // // htmlspecialchars(string)

        // var_dump($id);

        // $id = addslashes($id);

        // var_dump($id);
        // 
        // 
        // $str = "11w or 1=1";

        // $id = intval($str);

        // var_dump($id);


        // $sql = "select * from userq where id='{$id}'";

        // var_dump($sql);

        // var_dump($_SESSION);

        // $users = M()->query($sql);

        // var_dump($users);
        // 
        // $Verify = new \Think\Verify('xbs');
        // $Verify->entry();

    }
    public function index(){

    	$time = strtotime('-30 days');
    	$sql = "select count(t1.id) cn,t2.nikename,t2.face,t2.id from answer t1 LEFT JOIN `user` t2 on t1.uid=t2.id where t1.create_time>'{$time}' GROUP BY t1.uid ORDER BY cn desc limit 12";
    	$users = M()->query($sql);

        $this->gethots();

    	$this->assign('users',$users);

    	$count      = M('question')->count();
    	// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,5);// 实例化分页类 传入总记录数和每页显示的记录数(25)
		$show       = $Page->show();// 分页显示输出

		// var_dump($Page->firstRow);
		// var_dump($Page->listRows);

		// echo($show);exit;


    	$sql ="select t1.*,t2.nikename,t2.face,t3.cname from question t1 left join user t2 on t1.uid=t2.id left join category t3 on t1.cid=t3.id order by t1.top desc,t1.create_time desc limit ".$Page->firstRow.",".$Page->listRows;

    	$questions = M()->query($sql);

    	$this->assign('page',$show);
    	$this->assign('q',$questions);
        

        $this->display();
    }
}